import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:route_manager/wx_navigator.dart';
import 'package:wallet_home/page/theme/colors.dart';
import 'package:wallet_home/tools/common.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import 'package:wallet_home/widget/coins_manager.dart';

import '../image_r.dart';
import '../module_config.dart';

class WalletPageFirstCardWidget extends StatefulWidget {
  final String walletName;
  final String amount;

  WalletPageFirstCardWidget({Key key, this.walletName, this.amount})
      : super(key: key);

  @override
  _WalletPageFirstCardWidgetState createState() =>
      _WalletPageFirstCardWidgetState();
}

class _WalletPageFirstCardWidgetState extends State<WalletPageFirstCardWidget> {
  // num totalAssets = 0.00;
  String totalAmount;

  @override
  Widget build(BuildContext context) {
    // totalAssets = CoinManager().getTotalAssetsCNY();
    bool isBackUpMnemonic = SpUtil.getBool("verified_mnemonic");
    totalAmount = NumUtil.getNumByValueStr(widget.amount).toStringAsFixed(2);
    return Container(
//        transform: Matrix4.translationValues(0, 0, 0),
        margin: EdgeInsets.only(right: 6, left: 6),
        child: Card(
          //  color: Colors.red,
          elevation: 0.5,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(16.0))),
          child: Stack(
            overflow: Overflow.clip,
            children: [
              Positioned(
                child: Text.rich(TextSpan(children: [
                  WidgetSpan(
                      child: Container(
                        child: Image.asset(ImageR.imagesSoftWalletIcon,
                            width: 20,
                            height: 20,
                            fit: BoxFit.fill,
                            color: ThemeUtils.getThemeColor(
                                context: context,
                                brightnessColor: Colors.grey[800],
                                darkColor: Colors.white),
                            package: ModuleConfig.moduleName),
                      ),
                      alignment: PlaceholderAlignment.middle),
                  WidgetSpan(
                      child: Padding(
                          padding: EdgeInsets.only(left: 5),
                          child: Text(widget.walletName,
                              style: TextStyle(fontSize: 14)))),
                  WidgetSpan(
                      alignment: PlaceholderAlignment.middle,
                      child: Offstage(
                        offstage: isBackUpMnemonic,
                        child: Padding(
                            padding: EdgeInsets.only(left: 10),
                            child: GestureDetector(
                              onTap: () {
                                WXNavigator.pushNamed(
                                    context: context,
                                    routeName: '/checkPINPage',
                                    moduleName: "wallet_authentication",
                                    arguments: {
                                      'isHiddenBack': false,
                                      'onCallBack': (String value) {
                                        WXNavigator().popAndPushNamed(
                                            "/mnemonicBackup",
                                            context: context,
                                            moduleName: "wallet_authentication",
                                            arguments: 1);
                                      }
                                    });
                              },
                              child: Container(
                                  decoration: BoxDecoration(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(3)),
                                    color: Colours.payee_button,
                                  ),
                                  padding: EdgeInsets.all(2),
                                  child: Text(
                                      "${WXLang.$t("home_backup_wallet", package: ModuleConfig.moduleName)}",
                                      style: TextStyle(
                                          fontSize: 10,
                                          color: Colors.grey[200]))),
                            )),
                      )),
                ])),
                top: 20,
                left: 30,
              ),
              Positioned(
                child: InkWell(
                  child: Icon(
                    Icons.add,
                    color: ThemeUtils.getThemeColor(
                        context: context,
                        brightnessColor: Colors.grey[800],
                        darkColor: Colors.grey[400]),
                  ),
                  onTap: () {
                    WXNavigator.pushNamed(
                        moduleName: 'wallet_home', routeName: '/wallet_search');
                  },
                ),
                top: 20,
                right: 50,
              ),
              Positioned(
                child: InkWell(
                  child: Text("...", style: TextStyle(fontSize: 25)),
                  onTap: () {
                    WXNavigator.pushNamed(routeName: '/walletDetailPage');
                  },
                ),
                top: 10,
                right: 20,
              ),
              Positioned(
                child: Divider(
                  height: 0.5,
                  thickness: 0.5,
                ),
                bottom: 50,
                left: 0,
                right: 0,
              ),
              Positioned(
                  child: Text.rich(TextSpan(children: [
                    TextSpan(
                        text: _splitAmount(totalAmount)[0],
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 24,
                            wordSpacing: 0.002)),
                    TextSpan(
                        text: ".${_splitAmount(totalAmount)[1]}",
                        style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                            letterSpacing: 1)),
                    WidgetSpan(
                        child: Padding(
                      padding: EdgeInsets.only(left: 10),
                      child: Text(
                        "CNY",
                        style: TextStyle(fontSize: 18),
                      ),
                    ))
                  ], style: TextStyle(fontSize: 18))),
                  left: 30,
                  bottom: 70),
              Positioned(
                child: Container(
                  height: 50,
                  width: 200,
                  child: Row(
                    children: [
                      Expanded(
                          child: GestureDetector(
                        child: Container(
                            color: Color(0x00ffffff),
                            alignment: Alignment.center,
                            child: Text(
                              "${WXLang.$t("home_transfer", package: ModuleConfig.moduleName)}",
                              style: TextStyle(fontSize: 14),
                            )),
                        onTap: () {
                          WXNavigator.pushNamed(
                              context: context,
                              routeName: "/wallet_coin_select",
                              arguments: {Constant.isTransfer: true});
                        },
                      )),
                      VerticalDivider(
                        width: 0.5,
                        thickness: 0.5,
                      ),
                      Expanded(
                          child: GestureDetector(
                        child: Container(
                            color: Color(0x00ffffff),
                            alignment: Alignment.center,
                            child: Text(
                              "${WXLang.$t("home_receive", package: ModuleConfig.moduleName)}",
                              style: TextStyle(fontSize: 14),
                            )),
                        onTap: () {
                          WXNavigator.pushNamed(
                              context: context,
                              routeName: "/wallet_coin_select",
                              arguments: {
                                Constant.isTransfer: false,
                              });
                        },
                      )),
                    ],
                  ),
                ),
                bottom: 0,
                left: 0,
                right: 0,
              )
            ],
          ),
        ));
  }

  List<String> _splitAmount(String amount) {
    if (amount.isEmpty) return [];
    List<String> list = List();
    if (amount.contains(".")) {
      list = amount.split(".");
    }
    return list;
  }
}
